/**
 *  编辑前验证和新增前验证
 */
import {
  httpAction,
  getAction,
  postAction
} from '@/api/manage'
export const SubmitOnchangMixin = {
  props: ['EnhanceJS'],
  data() {
    return {
      formData: '',
    }
  },
  methods: {
    oNvisible() {
      this.visible = false
      this.$emit('ok')
    },
    // 提交验证 url验证接口api  method验证类型    httpurl表单提交url method表单提交类型
    modalFunAjaxOnchang(url, method, httpurl, method1) {
      const that = this;
      console.log(that.formData)
      let p = new Promise((resolve, reject) => {
        httpAction(url, that.formData, method).then((res) => {
          if (res.success) {
            resolve(true);
          } else {
            reject(res.msg)
          }
        }).finally(() => {
          that.confirmLoading = false;
        })
      })
      p.then((data) => {
        that.modalFrom(httpurl, that.formData, method1)
      }, (err) => {
        that.$message.warning(err);
      });
    },
    // httpurl  提交表单的api formData提交的数据  method1提交的类型
    modalFrom(httpurl, formData, method1) {
      const that = this
      httpAction(httpurl, that.formData, method1).then((res) => {
        if (res.success) {
          that.$message.success(res.msg);
          that.$emit('ok');
          that.close();
        } else {
          that.$message.warning(res.msg);
        }
      }).finally(() => {
        that.confirmLoading = false;
      })
    },

    modalGetHttp(httpurl, formData) {
      const that = this
      return getAction(httpurl, formData).then((res) => {
        if (res.success) {
          return res
        } else {
          that.$message.warning(res.msg)
        }
      })
    },
    modalPostHttp(httpurl, formData) {
      const that = this
      return postAction(httpurl, formData).then((res) => {
        if (res.success) {
          return res
        } else {
          that.$message.warning(res.msg)
        }
      })
    },

  }

}